<template>
  <div class="index">
    <div class="formBox">
        <p class="item"><span class="name">地区名称 ：</span><input v-model="date.name" class="slong" placeholder="请输入内容"></input></p>
        <p class="item"><span class="name">地区code ：</span><input v-model="date.code" class="slong" placeholder="请输入内容"></input></p>
        <p class="item inputBox"><button @click="submit" class="submitInput">确定</button><button @click="empty" class="emptyInput">重置</button></p>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import axios from 'axios'
import { Get, Post ,Put ,Delete} from '@/config/api'

export default {
  name: 'index',
  data() {
    return {
        date:{
          name:'',
          code:''
        }
    }
  },
  computed:{
    //检查表单
    VueFrom(){
      if(this.Input(this.date.name)&&this.Input(this.date.code)){
        return true
      }else{
        return false
      }
    }
  },
  methods: {
    //提交
    async submit() {
      if(this.VueFrom&&this.Check()){
        let data={
              "parent_id":0,
              "name":this.date.name,
              "code":this.date.code
        }
        let reg=await Post('/base/region',this.$store.state.token,data)
        alert('添加成功')
        this.$router.push('/addressList')
      }else{
        alert('请正确填写信息')
      }

    },
    //清空
    empty() {
      for(var key in this.date){
        this.date[key]=''
      }
    }

  }
}

</script>

